package com.quanyan.club.web;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.club.entity.vo.resp.RespClubWeekTask;
import com.quanyan.club.service.ClubTaskService;
import com.quanyan.common.exception.BizException;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * Created by yue.yuan on 2016/9/26.
 */
@RestController
@RequestMapping("/api/club/task")
public class ClubTaskController extends BaseController{

    @Autowired
    private ClubTaskService clubTaskService;

    @RequestMapping(value = "/week", method = RequestMethod.POST)
    public String queryClubWeekTask(@RequestBody Map<String, Object> map,
                                    BindingResult bindingResult, HttpServletRequest request)
    {
        int uid = getUid(request, true);
        if (!map.containsKey("clubId")){
            return JSONObject.toJSONString(APIResponse.returnFail("参数为空"));
        }
        RespClubWeekTask respClubWeekTask = clubTaskService.getClubWeekTaskById(MapUtils.getInteger(map, "clubId"), uid);
        if(null == respClubWeekTask)
        {
            return JSONObject.toJSONString(APIResponse.returnFail("这是个幽灵俱乐部"));
        }
        return JSONObject.toJSONString(APIResponse.returnSuccess(respClubWeekTask),
                SerializerFeature.WriteNullBooleanAsFalse,
                SerializerFeature.WriteNullListAsEmpty,
                SerializerFeature.WriteNullNumberAsZero,
                SerializerFeature.WriteMapNullValue,
                SerializerFeature.WriteNullStringAsEmpty);
    }
}
